package com.lanyun.carworld.model.vo;

import com.lanyun.carworld.model.entity.User;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用户视图（脱敏）
 */
@Data
@Builder
public class UserVO implements Serializable {

    /**
     * 用户昵称
     */
    private String userName;

    /**
     * 用户头像
     */
    private String userAvatar;

    private String userPhone;

    private String userEmail;

    private String gender;

    /**
     * 用户简介
     */
    private String userProfile;


    private static final long serialVersionUID = 1L;

    public static List<UserVO> convertEntityList(List<User> userList) {

        List<UserVO> userVOList = null;
        if (userList != null && userList.size() > 0) {
            userVOList = new ArrayList<>();
            for (User user : userList) {
                userVOList.add(convertEntity(user));
            }
        }

        return userVOList;

    }

    private static UserVO convertEntity(User user) {
        UserVO userVO = null;
        if (user != null) {
            userVO = UserVO.builder()
                    .userName(user.getUserName())
                    .userAvatar(user.getUserAvatar())
                    .userPhone(user.getUserPhone())
                    .userEmail(user.getUserEmail())
                    .gender(user.getGender())
                    .userProfile(user.getUserProfile())
                    .build();
        }
        return userVO;
    }
}